<template>
  <div style="padding:0px 5px;" class="root">
    <h4>{{imgInfo.title}}</h4>
    <p>
      <span class="time">发表时间: {{imgInfo.add_time | dateFormat}}</span>
      <span class="click">点击: {{imgInfo.click}}</span>
    </p>
    <hr />
    <ul>
      <li v-for="(item,index) in imgList" :key="item.id">
        <img :src="item.src" @click="tap(index)" />
      </li>
    </ul>
    <div class="detail-content" v-html="imgInfo.content"></div>
    <comment-view></comment-view>
  </div>
</template>

<script>
import Vue from 'vue'
import { ImagePreview, Toast } from 'vant'
import { mapState, mapMutations } from 'vuex'

Vue.use(ImagePreview)
Vue.use(Toast)
export default {
  data () {
    return {
      imgList: [],
      imgInfo: {},
      show: false,
      index: 2,
      images: [],
      commentList: [],
      commentPageNum: 1
    }
  },
  created () {
    this.getimgList()
    this.getimgInfo()
    this.getcommentList()
  },
  methods: {
    ...mapMutations(['setCommentList']),
    // 图片
    async getimgList () {
      const { data: res } = await this.$http.get('/api/getthumimages/' + this.photoListId)
      this.imgList = res.message
    },
    // 标题
    async getimgInfo () {
      const { data: res } = await this.$http.get('/api/getimageInfo/' + this.photoListId)
      this.imgInfo = res.message[0]
    },
    tap (index) {
      for (let i = 0; i < this.imgList.length; i++) {
        this.images[i] = this.imgList[i].src
      }

      ImagePreview({
        images: this.images,
        startPosition: index
      })
    },
    // 获取评论信息
    async getcommentList () {
      const res = await this.$http.get('/api/getcomments/' + this.photoListId + '?pageindex=1')
      this.commentList = res.data.message
      this.setCommentList(this.commentList)
    }
  },
  computed: {
    ...mapState(['photoListId'])
  }
}
</script>

<style scoped lang="less">
.root {
  margin-top: 47px;
}
div {
  display: block;
  h4 {
    display: block;
    font-weight: bold;
  }
  h4[data-v-760b9a46] {
    text-align: center;
    color: #26a2ff;
    font-size: 15px;
  }
  p {
    overflow: hidden;
    display: block;
    -webkit-margin-before: 1em;
    -webkit-margin-after: 1em;
    -webkit-margin-start: 0px;
    -webkit-margin-end: 0px;
    .time {
      float: left;
      font-size: 13px;
      color: #8f8f94;
    }
    .click {
      float: right;
      font-size: 13px;
      color: #8f8f94;
    }
  }
  hr {
    display: block;
    unicode-bidi: isolate;
    overflow: hidden;
    border-style: inset;
    border-width: 1px;
  }
  ul {
    display: block;
    list-style: none;
    margin: 10px 0;
    padding: 0 5px;
    overflow: hidden;
    li {
      float: left;
      width: 33.3333%;
      padding: 5px;
      box-sizing: border-box;
      display: list-item;
      text-align: -webkit-match-parent;
      img {
        width: 100%;
        box-shadow: 1px 0 8px 1px rgba(0, 0, 0, 0.3);
      }
    }
  }
  .van-cell-group {
    background-color: #fff;
  }
  [class*="van-hairline"] {
    position: relative;
  }
  .van-field {
    height: 100px;
    border: 1px solid #ccc;
  }
  .van-cell__value--alone {
    color: #323233;
    text-align: left;
  }
  .van-field__body {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
  }
  .van-field__control {
    display: block;
    box-sizing: border-box;
    width: 100%;
    margin: 0;
    padding: 0;
    color: #323233;
    text-align: left;
    background-color: transparent;
    border: 0;
    resize: none;
  }
  .van-button {
    width: 100%;
    margin: 5px 0;
  }
  .van-button--normal {
    padding: 0 15px;
    font-size: 14px;
  }
  .van-button--info {
    color: #fff;
    background-color: #1989fa;
    border: 1px solid #1989fa;
  }
  .van-button {
    position: relative;
    display: inline-block;
    box-sizing: border-box;
    height: 44px;
    margin: 0;
    padding: 0;
    font-size: 16px;
    line-height: 42px;
    text-align: center;
    border-radius: 2px;
    -webkit-appearance: none;
    -webkit-text-size-adjust: 100%;
  }

  button,
  input,
  textarea {
    color: inherit;
    font: inherit;
  }

  input {
    align-items: flex-start;
    text-align: center;
    cursor: default;
    color: buttontext;
    background-color: buttonface;
    box-sizing: border-box;
    padding: 2px 6px 3px;
    border-width: 2px;
    border-style: outset;
    border-color: buttonface;
    border-image: initial;
  }

  input,
  textarea,
  select,
  button {
    text-rendering: auto;
    color: initial;
    letter-spacing: normal;
    word-spacing: normal;
    text-transform: none;
    text-indent: 0px;
    text-shadow: none;
    display: inline-block;
    text-align: start;
    margin: 0em;
    font: 400 13.3333px Arial;
  }

  button {
    -webkit-appearance: button;
  }
  .van-button:before {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background-color: #000;
    border: inherit;
    border-color: #000;
    border-radius: inherit;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    opacity: 0;
    content: " ";
  }

  .van-button--hairline:after {
    border-color: inherit;
    border-radius: 4px;
  }
  .van-hairline--surround:after {
    border-width: 1px;
  }
  .title {
    height: 30px;
    background-color: #ccc;
    font-size: 12px;
    line-height: 30px;
  }
  .title span {
    margin-right: 6px;
  }
  .body {
    line-height: 35px;
    text-indent: 2em;
    font-size: 12px;
  }
}
</style>
